package com.company;

import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
	// write your code here
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入一个数字用判断是否为回文数:");
        int num = sc.nextInt();
        if(isPalindrome(num)){
            System.out.println(num + "是一个回文数");
        }else{
            System.out.println(num + "不是一个回文数");
        }
    }
    public static boolean isPalindrome(int x) {
        if(x < 0){
            return false;
        }else{
            int[] tmp = new int[10];
            int count = 0;
            for(int i = 0; x != 0; i++){
                tmp[i] = x % 10;
                x = x / 10;
                count++;
            }
            int left = 0;
            int right = count - 1;
            while(left <= right){
                if(tmp[left] == tmp[right]){
                    left++;
                    right--;
                }else{
                    break;
                }
            }
            if(left > right)
                return true;
            else
                return false;
        }
    }
}
